package districting;

import com.vividsolutions.jts.geom.*;

public class Location {

   private static double STANDARD_PARALLEL = Math.toRadians(-30.0);

   private static double COS_STANDARD_PARALLEL = Math.cos(STANDARD_PARALLEL);

   private float latitude;

   private float longitude;

   public Location(float latitude, float longitude) {
      this.latitude = latitude;
      this.longitude = longitude;
   }

   /**
    * @return the latitude
    */
   public float getLatitude() {
      return latitude;
   }

   /**
    * @param latitude
    *           the latitude to set
    */
   public void setLatitude(float latitude) {
      this.latitude = latitude;
   }

   /**
    * @return the longitude
    */
   public float getLongitude() {
      return longitude;
   }

   /**
    * @param longitude
    *           the longitude to set
    */
   public void setLongitude(float longitude) {
      this.longitude = longitude;
   }

   public double distanceTo(Location l2) {
      double lat1 = Math.toRadians(latitude);
      double long1 = Math.toRadians(longitude);
      double lat2 = Math.toRadians(l2.latitude);
      double long2 = Math.toRadians(l2.longitude);

      double R = 6371;

      return R
            * Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1)
                  * Math.cos(lat2) * Math.cos(long1 - long2));

   }

   /**
    * Crappy function - for simple bitmaps.
    * 
    * @param resolution
    * @param minLong
    * @param maxLong
    * @return
    */
   public int convertToX(int resolution, float minLong, float maxLong) {
      return Math.round(resolution * (longitude - minLong));
   }

   /**
    * 
    * Crappy function for simple bitmaps.
    * 
    * @param resolution
    * @param minLat
    * @param maxLat
    * @return
    */
   public int convertToY(int resolution, float minLat, float maxLat) {
      return Math.round(resolution * (latitude - minLat));
   }

   public Coordinate convertToCoordinate() {
      return new Coordinate(longitude, latitude);
   }

}
